package com.iptv.grape.event;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

public class KeyEventArgs {
    private KeyEventData data;
    private String eventName = "KeyEvent";
    private Long sendTime;

    public KeyEventArgs(String name,int value){
        this.sendTime = System.currentTimeMillis();
        this.data = new KeyEventData(name,value);
    }

    public String toJson(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }

    public static String getSecondTimes(){
        return String.format("%010d", getSecondTimesLong());
    }
    public static long getSecondTimesLong(){
        String times="";
        return System.currentTimeMillis()/1000;

    }

    private static HashMap<String,String> keyList = new HashMap<String,String>();

    static {
        keyList.put("4",new KeyEventArgs("KEYCODE_BACK_4",4).toJson());
        keyList.put("19",new KeyEventArgs("KEYCODE_DPAD_UP_19",19).toJson());
        keyList.put("20",new KeyEventArgs("KEYCODE_DPAD_DOWN_20",20).toJson());
        keyList.put("21",new KeyEventArgs("KEYCODE_DPAD_LEFT_21",21).toJson());
        keyList.put("22",new KeyEventArgs("KEYCODE_DPAD_RIGHT_22",22).toJson());
        keyList.put("66",new KeyEventArgs("KEYCODE_ENTER_66",66).toJson());
    }

    public static boolean containsKey(int keyCode){
        return keyList.containsKey(keyCode + "");
    }

    public static String getKeyEventArgs(int keyCode){
        return keyList.get(keyCode + "");
    }
}


